
import org.w3c.dom.Text;

import javax.swing.*;
        import java.awt.*;
        import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;
public class Save extends JPanel implements ActionListener {
    private JButton backBtn;
    private JButton sure;
    private Atmtest frame;
    private double money;
    private JTextField cunqian;
    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

    }

    public Save(Atmtest frame){
        this.frame = frame;
        this.setLayout(null);
        this.setOpaque(false);

        cunqian = new JTextField();
        cunqian.setBounds(180, 500, 200, 30);
        this.add(cunqian);

        sure = new JButton(Util.getIcon("/img/buttonSure.jpg"));
        sure.setBounds(900, 400, 100, 50);
        this.add(sure);
        sure.addActionListener(this);

        backBtn = new JButton(Util.getIcon("/img/buttonOff.jpg"));
        backBtn.setBounds(900, 330, 100, 50);
        this.add(backBtn);
        backBtn.addActionListener(this);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(backBtn == e.getSource()){
            frame.switchPanel("menu");
        }
        if (sure == e.getSource()){
            frame.getSave().getMoney();
            cunqian.setText("");
        }
    }

    public void getMoney(){
        money += Integer.parseInt(cunqian.getText());
        frame.getUsers().get(frame.getID()).setBalance(money);
    }

    public void setMoney() {
        this.money = frame.getUsers().get(frame.getID()).getBalance();
    }
}